﻿using UnityEngine;
using System.Collections;
using Spine.Unity;

public class SpineAnimationController : MonoBehaviour {

	private SkeletonAnimation skeletonAnimation;

	// Use this for initialization
	void Start () {
		skeletonAnimation = GetComponent<SkeletonAnimation> ();
		if (skeletonAnimation == null) {
			Debug.LogWarning (gameObject.name + "can not find component SkeletonAnimation!");
		}
	}

	public void PlayBaseLoopAnimation(string animationName) {
		if (skeletonAnimation == null)
			skeletonAnimation = GetComponent<SkeletonAnimation> ();
		skeletonAnimation.state.SetAnimation (0, animationName, true);
	}

	public void PlayAnimation(string animationName, bool isLoop) {
		if (skeletonAnimation == null)
			skeletonAnimation = GetComponent<SkeletonAnimation> ();
		skeletonAnimation.state.SetAnimation (1, animationName, isLoop);
	}

	public void StopBaseLoopAnimation() {
		if (skeletonAnimation == null)
			skeletonAnimation = GetComponent<SkeletonAnimation> ();
		skeletonAnimation.state.ClearTrack (0);
	}

	public void StopAnimation() {
		if (skeletonAnimation == null)
			skeletonAnimation = GetComponent<SkeletonAnimation> ();
		skeletonAnimation.state.ClearTrack (1);
	}
}
